/* raise()函数使用 */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

static void sig_handler(int sig)
{
    printf("Received signal: %d\n", sig);
}

int main(int argc, char const *argv[])
{
    struct sigaction sig = {0};
    int ret;

    sig.sa_handler = sig_handler; 
    sig.sa_flags = 0;
    ret = sigaction(SIGINT, &sig, NULL);
    if (-1 == ret) {
        perror("sigaction error!");
        exit(-1);
    }

    for (;;) {
        /* 向自身发送 SIGINT信号 */
        if (0 != raise(SIGINT)) {
            printf("raise error!");
            exit(-1);
        }

        sleep(3); /* 每隔3s发送一次*/
    }
    
    exit(0);
}
